<template>
	<view>
		<uni-rate value="4"></uni-rate>
		<uni-fab @fabClick=""></uni-fab>
		<view class="cake-list">
			<cake-item v-for="item in list" :gdata="item" :key="item.objectId"/>
		</view>
		
	</view>
</template>

<script setup>
import { ref } from "vue";
import { cakeGet } from "../../api/cake";
import { ID, KEY } from "../../config";
import { $http } from "../../utils/http";
import {onReachBottom,onPullDownRefresh} from '@dcloudio/uni-app'
const list = ref([])
let page = 1
cakeGet().then(res=>{
	list.value = res.data.results
	console.log(111);
	page++
})
onReachBottom(()=>{
	console.log('触底了');
	cakeGet(page).then(res=>{
		let {results} = res.data
		if(results.length){
			list.value = [
				...list.value,
				...res.data.results
			]
			page++
		}else{
			uni.showToast({
				title:'没有更多了',
				icon:'none'
			})
		}
	})
})

onPullDownRefresh(()=>{
	console.log('下拉刷新');
	list.value = []
	page = 1
	cakeGet().then(res=>{
		list.value = res.data.results
		uni.stopPullDownRefresh() 
	})
})

</script>

<style lang="scss">
.cake-list{
	padding: 15upx;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	.cake-item{
		width: 353upx;
	}
	image{
		width: 100%;
		height: 353upx;
	}
	
}
</style>
